package com.yeswater.multithread.chapter3.test3_1.chapter5;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * author : yeswater
 * date : 2023/10/23
 */

public class Run_5_1_1 {
    public static void main(String[] args) throws InterruptedException {

        long now = System.currentTimeMillis();
        System.out.println("now ==> " + now);

        long scheduleTime = now + 10000;
        System.out.println("schedule ==> " + scheduleTime);

        Task task = new Task();
        Timer timer = new Timer();
        Thread.sleep(1000);
        timer.schedule(task, new Date(scheduleTime));
        Thread.sleep(18000);
        timer.cancel();

        // Thread.sleep(Integer.MAX_VALUE);
    }

    private static class Task extends TimerTask {

        @Override
        public void run() {
            System.out.println("run task , time=" + System.currentTimeMillis());
        }
    }
}
